dojo.provide("ctrlspace.core.commands.RunCommand");
dojo.declare("ctrlspace.core.commands.RunCommand", ctrlspace.core.Plugin, {
	constructor: function() {
		this.dialog = null;
	},

	execute: function() {
		IDE.UI.setStatus('Running project...', ctrlspace.config.STATUS_PROGRESS);
		
		var projectId;
		if (IDE.getUI().tree.lastFocused.item.projectId != null) {
			projectId = IDE.getUI().tree.lastFocused.item.projectId[0];
		} else {
			projectId = IDE.getUI().tree.lastFocused.item.id[0];
		}
		
		var call = dojo.xhrPost({
			url: ctrlspace.config.projectManagerUrl,
			content: {
				command: "run",
				projectId: projectId
			},
			handleAs: 'json',
			load: dojo.hitch(this, this.runComplete)
		});
	},
	
	runComplete: function(response) {
		var port = response.port;
		var win = window.open("http://localhost:" + port + "/");
		IDE.UI.setStatus('Success.', ctrlspace.config.STATUS_SUCCESS, 3);
	}
});